package org.keyuan.struts1.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.keyuan.entity.Buyer;

public class BuyerForm extends ActionForm {
	private static final long serialVersionUID = -8285200177400086261L;
	private Buyer buyer = new Buyer();
	private String checkcode;
	private String pwd;
	private String lasturl;
	private String lasturl_method;
	public Buyer getBuyer() {
		return buyer;
	}

	public void setBuyer(Buyer buyer) {
		this.buyer = buyer;
	}

	public String getCheckcode() {
		return checkcode;
	}

	public void setCheckcode(String checkcode) {
		this.checkcode = checkcode;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors actionErrors = new ActionErrors();
		if(!"login".equals(request.getParameter("method"))){
		if (buyer.getEmail() == null || "".equals(buyer.getEmail())) {
			actionErrors.add("buyer.email", new ActionMessage("email.error"));
		}
		if (buyer.getPassword() == null || "".equals(buyer.getPassword())
				|| buyer.getPassword().length() < 6) {
			actionErrors.add("buyer.password", new ActionMessage(
					"password.error"));
		} else {
			if (pwd == null || "".equals(pwd) || pwd == buyer.getPassword()) {
				actionErrors.add("pwd", new ActionMessage("pwd.error"));
			}
		}
		if (checkcode == null || "".equals(checkcode)) {
			actionErrors.add("checkcode", new ActionMessage("code.error"));
		}
		}
		return actionErrors;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String getLasturl() {
		return lasturl;
	}

	public void setLasturl(String lasturl) {
		this.lasturl = lasturl;
	}

	public String getLasturl_method() {
		return lasturl_method;
	}

	public void setLasturl_method(String lasturlMethod) {
		lasturl_method = lasturlMethod;
	}
}
